home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_castucco.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  1.3 KB  |  44 lines

  1. /*
  2.  * castucco.sl -- dispacement shader for stucco.
  3.  *
  4.  * Description:
  5.  *   I call this "castucco" because it's the stuff on the walls *everywhere*
  6.  *   in Northern California.  I never really saw it on the East Coast,
  7.  *   but in CA it's truly ubiquitous.
  8.  * 
  9.  * Parameters:
  10.  *   freq - basic frequency of the texture
  11.  *   Km - amplitude of the mesas.
  12.  *   octaves - how many octaves of fBm to sum
  13.  *   trough, peak - define the shape of the valleys and mesas of the stucco.
  14.  *
  15.  * $Revision: 1.1 $    $Date: 2002/11/25 20:23:59 $
  16.  *
  17.  */
  18.  
  19. #include "k3d_noises.h"
  20. #include "k3d_displace.h"
  21.  
  22. displacement k3d_castucco(float freq = 1;
  23.               float Km = 0.2;
  24.               float octaves = 3;
  25.               float trough = -0.15, peak = 0.35)
  26. {
  27.   point Pshad;            /* Point to be shaded, in shader space */
  28.   float fwidth;            /* Estimated change in P between image samples */
  29.   float disp;            /* Amount to displace */
  30.  
  31.   /* Do texture calcs in "shader" space, get approximate filter size */
  32.   Pshad = freq * transform("shader", P);
  33.   fwidth = filterwidthp(Pshad);
  34.  
  35.   /* Compute some fractional Brownian motion */
  36.   disp = fBm(Pshad, fwidth, 3, 2, 0.6);
  37.  
  38.   /* Threshold the fBm and scale it */
  39.   disp = Km * smoothstep(trough, peak, disp);
  40.  
  41.   /* displace in shader space units */
  42.   N = Displace(normalize(N), "shader", disp, 1);
  43. }
  44.